#include <iostream>

using std::cout;
using std::endl;

class Complex
{
public:
    Complex(double dreal, double dimage)
    : _dreal(dreal)
    , _dimage(dimage)
    {   cout << "Complex(double,double)" << endl;   }

    void print() const
    {
        cout << _dreal << " + " << _dimage << " i" << endl;
    }

//private:
    double _dreal;
    double _dimage;
};

//运算符重载之普通函数
Complex operator+(const Complex & lhs, const Complex & rhs)
{
    Complex tmp(lhs._dreal + rhs._dreal, lhs._dimage + rhs._dimage);
    return tmp;
}

int main()
{
    int a = 1, b = 2;
    int c = a + b;//内置类型的运算符不能重载
    cout << "c:" << c << endl;

    Complex c1(1, 2), c2(3, 4);
    cout << "c1:";
    c1.print();
    cout << "c2:";
    c2.print();

    //现在没有相应的运算符可以使用
    Complex c3 = c1 + c2;
    cout << "c3:";
    c3.print();

    return 0;
}

